package com.yanqu.road.server.cmd.activity.xingyoushanshui.cross;

import com.yanqu.road.entity.activity.youxing.XingYouShanShuiUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XingYouShanShuiProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.shanshui.XingYouShanShuiModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = Protocol.S_XING_YOU_SHAN_SHUI_TEAM_DATA_SYNC,desc = "队伍数据同步")
public class ShanShuiTeamDataSyncCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        XingYouShanShuiProto.CrossShanShuiTeamDataSync sync = XingYouShanShuiProto.CrossShanShuiTeamDataSync.parseFrom(yanQuMessage.getBytes());
        for (long uid : sync.getUserIdList()) {
            GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(uid);
            if(onlinePlayer != null){
                XingYouShanShuiUserData userData = onlinePlayer.getModule(XingYouShanShuiModule.class).getUserData();
                if(userData != null){
                    userData.setTeamTotalEnergy(sync.getTotalEnergy());
                    userData.setTeamTotalSilverCoin(sync.getTotalSilver());

                    //成就
                }
            }
        }
    }
}
